
//? promise实现
function sleep(time) {
    console.log("开始睡觉")
    return new Promise((resolve, reject) => {
        setTimeout(() => {

            resolve("睡醒了")
        },time)
    })
}


sleep(2000).then(res => console.log(res))


//? 正常实现

function sleepy(time) {
    console.log('开始睡觉')
    const now = Date.now()
    while (now + time > Date.now()) {

    }
    console.log('睡醒了')
}
sleepy(2000)
